﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sunny.Lib
{
    public class EnvironmentHelper
    {
        public static string CurrentDirSymbol = "%CurrentDir%";
        // the executable file path.
        public static string CurrentDir
        {
            get
            {
                return new System.IO.DirectoryInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).Parent.FullName.TrimEnd('\\');
            }
        }

        public static string CurrentProjectDir
        {
            get
            {
                return new System.IO.DirectoryInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).Parent.Parent.Parent.FullName.TrimEnd('\\');
            }
        }

        public static string CurrentSolutionDir
        {
            get
            {
                return new System.IO.DirectoryInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).Parent.Parent.Parent.Parent.FullName.TrimEnd('\\');
            }
        }

        public static string ExpandEnvironmentVariables(string path)
        {
            string expandPath = path;

            expandPath = Environment.ExpandEnvironmentVariables(path);
            if (expandPath.Contains(CurrentDirSymbol))
            {
                expandPath = expandPath.Replace(CurrentDirSymbol, CurrentDir);
            }

            return expandPath;
        }

        public static string ReplaceByEnvironmentVariables(string expandPath)
        {
            string path = expandPath;

            path = path.Replace(CurrentDir, CurrentDirSymbol);

            return path;
        }
    }
}
